package com.origin.utils.activity

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import com.origin.utils.R
import com.origin.utils.ScreenAdaptationUtil
import com.origin.utils.ToastUtils
import kotlinx.android.synthetic.main.activity_screen_adaptation.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import java.lang.NumberFormatException

class ScreenAdaptationActivity : AppCompatActivity() {
    companion object {
        fun toScreenAdaptationPage(activity: AppCompatActivity, designWidth: Float = 360f) {
            val intent = Intent(activity, ScreenAdaptationActivity::class.java);
            intent.putExtra("designWidth", designWidth)
            activity.startActivity(intent)
        }
    }
    private var scope = CoroutineScope(Dispatchers.Default)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        if (intent.hasExtra("designWidth")) {
            val designWidth = intent.getFloatExtra("designWidth", 500f)
            ScreenAdaptationUtil.init(this, designWidth)
        }

        setContentView(R.layout.activity_screen_adaptation)

    }

    fun modifyDesignWidth(view: View) {
        try {
            val modifyDesignWidthEdStr = modifyDesignWidthEd.text.toString();
            val num = modifyDesignWidthEdStr.toFloat();
            toScreenAdaptationPage(this, num)
            finish()
        } catch (e: NumberFormatException) {
            ToastUtils.showSystem(this.application, "请输入数字")
        }

    }
}